﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using java.util;
using lineage2.commons.util;

namespace Game.templates.skill.restoration
{
    public  sealed class RestorationInfo
    {
        private int _skillId;
	    private int _skillLvl;
	    private int _itemConsumeId;
	    private int _itemConsumeCount;
	    private IEnumerable<List> _restorationGroups;

	    public RestorationInfo(int skillId, int skillLvl, int itemConsumeId, int itemConsumeCount)
	    {
		    this._skillId = skillId;
		    this._skillLvl = skillLvl;
		    this._itemConsumeId = itemConsumeId;
		    this._itemConsumeCount = itemConsumeCount;
		    this._restorationGroups = new[] {new ArrayList()};
	    }

	    public int getSkillId()
	    {
		    return this._skillId;
	    }

	    public int getSkillLvl()
	    {
		    return this._skillLvl;
	    }

	    public int getItemConsumeId()
	    {
		    return this._itemConsumeId;
	    }

	    public int getItemConsumeCount()
	    {
		    return this._itemConsumeCount;
	    }

	    public void addRestorationGroup(RestorationGroup group)
	    {
	        List<List> temp = _restorationGroups.ToList();
            temp.Add(group);
	        _restorationGroups = temp.ToArray();
		    //this._restorationGroups.add(group);
	    }

	    public List getRandomGroupItems()
	    {
		    double chancesAmount = this._restorationGroups.Cast<RestorationGroup>().Sum(@group => @group.getChance());
	        if (Rnd.chance(chancesAmount))
		    {
			    double chanceMod = (100.0D - chancesAmount) / this._restorationGroups.Count();
			    List successGroups = new ArrayList();
			    int tryCount = 0;
			    while (successGroups.isEmpty())
			    {
				    tryCount++;
				    foreach (RestorationGroup group in this._restorationGroups)
				    {
					    if (tryCount % 10 == 0)
						    chanceMod += 1.0D;
					    if (Rnd.chance(group.getChance() + chanceMod))
						    successGroups.add(group);
				    }
			    }
			    RestorationGroup[] groupsArray = (RestorationGroup[])successGroups.toArray(new RestorationGroup[successGroups.size()]);
			    return groupsArray[Rnd.get(groupsArray.Length)].getRestorationItems();
		    }
		    return new ArrayList(0);
	    }
    }
}
